package blog.service.thread;

import blog.dao.mapper.ArticleMapper;
import blog.dao.pojo.Article;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class ThreadService {

    @Async("taskExecutor")
    public void updateViewCount(ArticleMapper articleMapper, Article article){

        Article newArticle = new Article();
        newArticle.setViewCounts(article.getViewCounts()+1);

        LambdaQueryWrapper<Article> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Article::getId,article.getId());
        wrapper.eq(Article::getViewCounts,article.getViewCounts());

        articleMapper.update(newArticle,wrapper);
    }
}
